package four;

public class A080 {

    //287.寻找重复数
    public int findDuplicate(int[] nums) {
        int fast=0,slow=0;
        while(true) {
            fast = nums[fast];
            fast = nums[fast];
            slow = nums[slow];
            if(slow==fast) break; //遇到环了
        }
        slow=0;
        while(slow!=fast) {
            slow = nums[slow];
            fast = nums[fast];
        }
        return fast;
    }
}
